package com.example.littleken.mytao.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by littleken on 2018/4/17.
 */
//主页滚动广告控件的初始化，和销毁
//妈个鸡，最难写就是滚动广告区了，都不知道自己写了啥
public class MainHeaderAdAdpter extends PagerAdapter{

    protected  Context context;//广告控件的成员变量
    protected  List<ImageView> images;

    public MainHeaderAdAdpter(Context context, List<ImageView>images){
        //构造方法
        this.context =context;
        this.images = images;
    }

    public int getCount() {
        //取得图片集合的大小
        return null!=images?images.size():0;
    }

    public Object instantiateItem(ViewGroup container, int position) {
        //初始化方法
        container.addView(images.get(position));
        return images.get(position);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //销毁方法
       container.removeView(images.get(position));
    }
}
